from __future__ import annotations

from dataclasses import dataclass
from math import cos, sin, radians, sqrt


def compute_span_and_drop(x1: float, y1: float, x2: float, y2: float) -> tuple[float, float]:
    """计算水平距离与高差。"""

    span = abs(x2 - x1)
    drop = y2 - y1
    return span, drop


def bearing_to_dxdy(distance_m: float, azimuth_deg: float) -> tuple[float, float]:
    """根据方位角与距离计算 dx, dy（平面坐标）。"""

    theta = radians(azimuth_deg)
    return distance_m * cos(theta), distance_m * sin(theta)


def wgs84_to_local(lat_deg: float, lon_deg: float, lat0_deg: float, lon0_deg: float, scale: float = 111000.0) -> tuple[float, float]:
    """极简WGS84到本地平面近似（小范围）。"""

    dx = (lon_deg - lon0_deg) * scale * cos(radians(lat0_deg))
    dy = (lat_deg - lat0_deg) * scale
    return dx, dy


